<template>
  <div class="newDrugs">
    <div class="titleP">
      <modules-title
        :title-name="$route.query.id == undefined ? '新增药品' : '编辑药品'"
      >
        <template slot="btn">
          <el-button class="border-btn" @click="goBack">取消</el-button>
          <el-button class="main-btn" type="primary" @click="saveDia"
            >保存
          </el-button>
        </template>
      </modules-title>
    </div>
    <div id="total-main" class="total-main">
      <div class="main">
        <div class="div">
          <h1 class="h1">
            基本信息<span v-if="wanrning == true" style="color:red">
              （该药品已存在,请核对,否则无法保存）</span
            >
          </h1>
        </div>
        <div class="form">
          <el-form
            ref="form1"
            inline
            :model="form"
            label-width="90px"
            :rules="rules"
          >
            <el-row>
              <el-col :span="8" class="left">
                <el-form-item prop="product_name" label="药品名称">
                  <el-autocomplete
                    :popper-append-to-body="false"
                    @blur="dataCheck('1')"
                    @focus="inputLenvo"
                    @input="inputLenvo"
                    @select="changeLenvo"
                    class="inline-input"
                    v-model="form.product_name"
                    :fetch-suggestions="
                      (queryString, cb) => {
                        querySearch(queryString, cb, 'product_name');
                      }
                    "
                    placeholder="请输入药品关键字"
                  ></el-autocomplete>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="center">
                <el-form-item prop="category_id" label="药品类型">
                  <el-select
                    v-model="form.category_id"
                    placeholder="请选择药品类型"
                  >
                    <el-option
                      v-for="item in optionsCategory"
                      :key="item.ID"
                      :label="item.category_name"
                      :value="item.ID"
                      :disabled="item.disabled"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="right">
                <el-form-item label="OTC" prop="">
                  <el-radio-group v-model="form.otc">
                    <el-radio border class="leftRadio" :label="true"
                      >是
                    </el-radio>
                    <el-radio border class="rightRadio" :label="false"
                      >否
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" class="left">
                <el-form-item label="包装规格" :prop="pack" class="norms">
                  <el-autocomplete
                    @select="dataCheck"
                    @blur="dataCheck"
                    @focus="inputLenvoOther('pack')"
                    @input="inputLenvoOther('pack')"
                    clearable
                    class="inline-input input-number-unit"
                    v-model="form.pack"
                    :fetch-suggestions="
                      (queryString, cb) => {
                        querySearch(queryString, cb, 'pack');
                      }
                    "
                    placeholder="请输入包装描述"
                  >
                    <el-select
                      class="number_unit"
                      slot="append"
                      @change="unitCheck"
                      clearable
                      v-model="form.number_unit"
                      placeholder="单位"
                      allow-create
                      filterable
                      :filter-method="unitCheck1"
                    >
                      <el-option
                        v-for="(item, index) in adv.number_unit"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-autocomplete>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="center">
                <el-form-item label="自定义分类" prop="self_category">
                  <el-autocomplete
                    @focus="selfCategoryLenvo"
                    @input="selfCategoryLenvo"
                    clearable
                    class="inline-input"
                    v-model="form.self_category"
                    :fetch-suggestions="
                      (queryString, cb) => {
                        querySearch(queryString, cb, 'self_category');
                      }
                    "
                    placeholder="请输入自定义分类"
                  ></el-autocomplete>
                </el-form-item>
                <!--  <el-input

                   clearable
                   class="inline-input"
                   v-model="form.self_category"
                   placeholder="请输入自定义分类"
                 ></el-input> -->
              </el-col>
              <el-col :span="8" class="right">
                <el-form-item label="状态" prop="">
                  <el-radio-group v-model="form.product_status">
                    <el-radio border class="leftRadio" :label="true"
                      >启用
                    </el-radio>
                    <el-radio border class="rightRadio" :label="false"
                      >停用
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" class="left">
                <el-form-item label="生产厂家" prop="production">
                  <el-autocomplete
                    @blur="dataCheck"
                    @change="dataCheck"
                    @focus="inputLenvoOther('production')"
                    @input="inputLenvoOther('production')"
                    clearable
                    class="inline-input"
                    v-model="form.production"
                    :fetch-suggestions="
                      (queryString, cb) => {
                        querySearch(queryString, cb, 'production');
                      }
                    "
                    placeholder="请输入生产厂家"
                  ></el-autocomplete>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="center">
                <el-form-item label="批准文号" prop="">
                  <el-autocomplete
                    @blur="dataCheck"
                    @change="dataCheck"
                    @focus="inputLenvoOther('approval')"
                    @input="inputLenvoOther('approval')"
                    clearable
                    class="inline-input"
                    v-model="form.approval"
                    :fetch-suggestions="
                      (queryString, cb) => {
                        querySearch(queryString, cb, 'approval');
                      }
                    "
                    placeholder="请输入批准文号"
                  ></el-autocomplete>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="right">
                <el-form-item label="药品条形码" prop="">
                  <el-input
                    clearable
                    class="inline-input"
                    v-model="form.bar_code"
                    placeholder="请输入药品条形码"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
      <div class="main" v-if="state.drugs_management.function_set != true">
        <div class="div">
          <h1 class="h1">库存销量设置</h1>
        </div>
        <div class="form">
          <el-form
            inline
            label-width="90px"
            ref="form2"
            :model="form"
            :rules="rules"
          >
            <el-row>
              <el-col :span="8" class="left">
                <el-form-item label="库存" prop="number" class="norms">
                  <el-input
                    @focus="inputClear('number')"
                    clearable
                    class="inline-input input"
                    v-model="form.number"
                    placeholder="请输入库存数量"
                  >
                    <span slot="append" class="select">{{ unit }} </span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="center">
                <el-form-item label="支持拆零" prop="">
                  <el-radio-group v-model="form.split_piece">
                    <el-radio
                      :disabled="$route.query.id != undefined"
                      border
                      class="leftRadio"
                      :label="true"
                      >是
                    </el-radio>
                    <el-radio
                      :disabled="$route.query.id != undefined"
                      border
                      class="rightRadio"
                      :label="false"
                      >否
                    </el-radio>
                  </el-radio-group>
                  <div
                    class="el-icon-warning splitPieceWarn"
                    v-if="$route.query.id == undefined"
                  >
                    <span>保存后不可更改</span>
                  </div>
                  <!--  <div class="el-icon-warning splitPieceWarn" v-else><span>不可更改</span></div> -->
                </el-form-item>
              </el-col>
              <el-col :span="8" class="right">
                <el-form-item label="拆零单位" class="norms" :prop="exchange">
                  <el-input
                    :disabled="form.split_piece ? false : true"
                    clearable
                    class="inline-input input-piece_num"
                    v-model="form.exchange"
                    @focus="exchangeFocus"
                    @blur="exchangeBlur"
                    placeholder="换算比"
                  >
                    <el-select
                      clearable
                      :disabled="form.split_piece ? false : true"
                      class="input-piece_unit"
                      slot="append"
                      @change="unitCheck"
                      v-model="form.piece_unit"
                      placeholder="小包装单位"
                      allow-create
                      filterable
                      :filter-method="unitCheck2"
                    >
                      <el-option
                        v-for="(item, index) in adv.piece_unit"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-input>

                  <el-input
                    v-model="unitEnd"
                    disabled
                    class="select"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" class="left">
                <el-form-item label="进货价" prop="buy_price" class="norms">
                  <div>
                    <el-input
                      @focus="inputClear('buy_price')"
                      clearable
                      class="inline-input input"
                      v-model="form.buy_price"
                      placeholder="请输入进货价格"
                    >
                      <span slot="append" class="select"
                        >{{ "元/" + form.number_unit }}
                      </span>
                    </el-input>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="center">
                <el-form-item label="处方价" prop="price" class="norms">
                  <div>
                    <el-input
                      @focus="inputClear('price')"
                      class="inline-input input"
                      v-model="form.price"
                      placeholder="请输入处方价格"
                    >
                      <span slot="append" class="select"
                        >{{ price_unit }}
                      </span>
                    </el-input>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="right">
                <el-form-item label="库存阈值" prop="min_num" class="norms">
                  <div>
                    <el-input
                      clearable
                      @focus="inputClear('min_num')"
                      class="inline-input input"
                      v-model="form.min_num"
                      placeholder="请输入库存阈值"
                    >
                      <span slot="append" class="select"
                        >{{ unit }}
                      </span></el-input
                    >
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" class="left">
                <el-form-item label="效期" prop="expire_time">
                  <el-date-picker
                    :picker-options="pickerOptions"
                    value-format="yyyy-MM-dd"
                    v-model="form.expire_time"
                    type="date"
                    placeholder="选择有效期"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="center">
                <el-form-item label="供应商" prop="">
                  <el-input
                    clearable
                    class="inline-input"
                    v-model="form.supplier"
                    placeholder="请输入供应商"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="right">
                <el-form-item label="货架码" prop="">
                  <el-input
                    clearable
                    class="inline-input"
                    v-model="form.shelf_no"
                    placeholder="请输入货架码"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
      <div class="main" v-else>
        <div class="div">
          <h1 class="h1">库存销量设置</h1>
        </div>
        <div class="form">
          <el-form
            ref="form3"
            :rules="rules"
            :model="form"
            inline
            label-width="90px"
          >
            <el-row>
              <el-col :span="8" class="left">
                <el-form-item label="库存阈值" prop="min_num" class="norms">
                  <el-input
                    clearable
                    @focus="inputClear('min_num')"
                    class="inline-input input"
                    v-model="form.min_num"
                    placeholder="请输入库存阈值"
                  >
                    <span slot="append" class="select"
                      >{{ unit }}
                    </span></el-input
                  >
                </el-form-item>
              </el-col>
              <el-col :span="8" class="center">
                <el-form-item label="支持拆零" prop="">
                  <el-radio-group v-model="form.split_piece">
                    <el-radio
                      :disabled="$route.query.id != undefined"
                      border
                      class="leftRadio"
                      :label="true"
                      >是
                    </el-radio>
                    <el-radio
                      :disabled="$route.query.id != undefined"
                      border
                      class="rightRadio"
                      :label="false"
                      >否
                    </el-radio>
                  </el-radio-group>
                  <div
                    class="el-icon-warning splitPieceWarn"
                    v-if="$route.query.id == undefined"
                  >
                    <span>保存后不可更改</span>
                  </div>
                  <!-- <div class="el-icon-warning splitPieceWarn" v-else><span>不可更改</span></div> -->
                </el-form-item>
              </el-col>
              <el-col :span="8" class="right">
                <el-form-item label="拆零单位" class="norms" :prop="exchange">
                  <el-input
                    :disabled="form.split_piece ? false : true"
                    clearable
                    class="inline-input input-piece_num"
                    v-model="form.exchange"
                    @focus="exchangeFocus"
                    @blur="exchangeBlur"
                    placeholder="换算比"
                  >
                    <el-select
                      clearable
                      :disabled="form.split_piece ? false : true"
                      class="input-piece_unit"
                      slot="append"
                      @change="unitCheck"
                      v-model="form.piece_unit"
                      placeholder="小包装单位"
                      allow-create
                      filterable
                      :filter-method="unitCheck2"
                    >
                      <el-option
                        v-for="(item, index) in adv.piece_unit"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-input>

                  <el-input
                    v-model="unitEnd"
                    disabled
                    class="select"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" class="left">
                <el-form-item label="处方价" prop="price" class="norms">
                  <div>
                    <el-input
                      clearable
                      class="inline-input input"
                      v-model="form.price"
                      @focus="inputClear('price')"
                      placeholder="请输入处方价格"
                    >
                      <span slot="append" class="select"
                        >{{ price_unit }}
                      </span>
                    </el-input>

                    <!--  <el-input
                        v-model="price_unit"
                        readonly
                        class="select"
                    ></el-input> -->
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="center">
                <el-form-item label="供应商" prop="">
                  <el-input
                    clearable
                    class="inline-input"
                    v-model="form.supplier"
                    placeholder="请输入供应商"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="right">
                <el-form-item label="货架码" prop="">
                  <el-input
                    clearable
                    class="inline-input"
                    v-model="form.shelf_no"
                    placeholder="请输入货架码"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
      <div class="main">
        <div class="div">
          <h1 class="h1">使用信息</h1>
        </div>
        <div class="form">
          <el-form
            inline
            :rules="rules"
            :model="form"
            ref="form5"
            label-width="95px"
          >
            <el-row>
              <el-col :span="8" class="left">
                <el-form-item prop="usage" label="用法">
                  <el-autocomplete
                    clearable
                    class="inline-input"
                    v-model="form.usage"
                    :fetch-suggestions="
                      (queryString, cb) => {
                        querySearch(queryString, cb, 'usage');
                      }
                    "
                    placeholder="请输入用法"
                  ></el-autocomplete>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="center">
                <el-form-item label="单次剂量" class="norms" prop="dose">
                  <el-input
                    @focus="inputClear('dose')"
                    clearable
                    class="inline-input dose"
                    v-model="form.dose"
                    placeholder="剂量数值"
                  ></el-input>

                  <el-autocomplete
                    clearable
                    class="inline-input dose_unit"
                    v-model="form.dose_unit"
                    :fetch-suggestions="
                      (queryString, cb) => {
                        querySearch(queryString, cb, 'dose_unit');
                      }
                    "
                    placeholder="剂量单位"
                  ></el-autocomplete>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="right">
                <el-form-item label="使用频次">
                  <el-autocomplete
                    clearable
                    class="inline-input"
                    v-model="form.rate"
                    :fetch-suggestions="
                      (queryString, cb) => {
                        querySearch(queryString, cb, 'rate');
                      }
                    "
                    placeholder="请输入使用频次"
                  ></el-autocomplete>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" class="left">
                <el-form-item
                  label="默认开药量"
                  prop="default_sell_number"
                  class="norms"
                >
                  <div>
                    <el-input
                      @focus="inputClear('default_sell_number')"
                      clearable
                      class="inline-input input"
                      v-model="form.default_sell_number"
                      placeholder="请输入默认开药量"
                    >
                      <el-select
                        class="default_sell_number_unit"
                        placeholder="单位"
                        slot="append"
                        v-model="form.default_sell_number_unit"
                      >
                        <el-option
                          v-for="item in default_sell_number_unit_options"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        >
                        </el-option>
                      </el-select>
                    </el-input>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="center">
                <el-form-item label="医嘱" prop="">
                  <el-autocomplete
                    clearable
                    class="inline-input"
                    v-model="form.advice"
                    :fetch-suggestions="
                      (queryString, cb) => {
                        querySearch(queryString, cb, 'advice');
                      }
                    "
                    placeholder="请填写医嘱"
                  ></el-autocomplete>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="right">
                <el-form-item prop="use_type" label="用药类型">
                  <el-select
                    clearable
                    v-model="form.use_type"
                    placeholder="请选择用药类型"
                  >
                    <el-option
                      v-for="item in optionsUse_type"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
    </div>
    <save-dialog :dialogVisible="dialogVisible">
      <template slot="btn">
        <el-button class="border-btn" @click="dialogVisible = false"
          >取 消
        </el-button>
        <el-button class="main-btn" type="primary" @click="save"
          >确 定
        </el-button>
      </template>
    </save-dialog>
  </div>
</template>
<script>
import saveDialog from "@/components/saveDialog.vue";
import modulesTitle from "@/components/modulesTitle.vue";
import {
  newDrugs,
  getDrugsDetail,
  getDrugsCategory,
  lenvo,
  lenvoOther,
  getJson,
  matchDefaultId,
  self_categoryLenvo,
  getDrugsDetailDefId
} from "@/api/drugsManagement.js";

export default {
  components: { modulesTitle, saveDialog },
  name: "newDrugs",
  data() {
    var numberCheck = (rule, value, callback) => {
      console.log(rule, value);

      if (value === "" || value == undefined) {
        switch (rule.field) {
          case "use_type":
            this.boole = false;
            callback(new Error("请选择用药类型"));
          case "number":
            callback(new Error("请输入库存数量"));
            break;
          case "buy_price":
            callback(new Error("请输入进货价"));
            break;
          case "price":
            callback(new Error("请输入处方价"));
            break;
          case "min_num":
            callback(new Error("请输入库存阈值"));
            break;

          case "exchange":
            if (this.rules.exchange[0].required == true) {
              callback(new Error("请输入换算比"));
            } else {
              callback();
            }

            break;
        }
      } else {
        switch (rule.field) {
          case "use_type":
            this.boole = true;
            callback();
            break;
          case "number":
            if (!/^[0-9]+$/.test(value)) {
              this.form.number = this.temp.number;

              callback();
            }

            let reg1 = /^[0-9]\d{0,5}$/;
            let flag1 = reg1.test(value);
            if (value == "00") {
              this.form.number = "0";
            }
            if (!flag1) {
              callback(new Error("请输入大于0的数,且最大999999"));
              break;
            }
            callback();
            this.temp.number = value;
            break;
          case "buy_price":
            this.form.buy_price = value.replace(
              new RegExp("(^[0]*)([0-9]+)", "g"),
              "$2"
            );
            let reg2 = /^[0-9]\d{0,7}(\.\d{0,3})?$/g;
            let flag2 = reg2.test(value);
            if (value == "00") {
              this.form.buy_price = "0";
            }
            if (!flag2) {
              if (/(\.\d{0,3})?$/g.test(value)) {
                callback(new Error("请输入数字，且小数位最多为3位"));
              }
              callback(new Error("请输入大于0的小数,且最大999999.999"));
            }
            if (value > 999999.999) {
              callback(new Error("进货价最大值为999999.999"));
            }
            callback();
            break;
          case "price":
            this.form.price = value.replace(
              new RegExp("(^[0]*)([0-9]+)", "g"),
              "$2"
            );
            let reg3 = /^[0-9]\d{0,7}(\.\d{0,2})?$/g;
            let flag3 = reg3.test(value);
            if (value == "00") {
              this.form.price = "0";
            }
            if (!flag3) {
              if (/(\.\d{0,2})?$/g.test(value)) {
                callback(new Error("请输入数字，且小数位最多为2位"));
              }
              callback(new Error());
            }
            if (value > 999999.999) {
              callback(new Error("处方价最大值为999999.99"));
            }
            callback();
            break;
          case "min_num":
            if (!/^[0-9]+$/.test(value)) {
              this.form.min_num = this.temp.min_num;
              callback();
              break;
            }

            this.form.min_num = value
              .replace(/\./, "")
              .replace(new RegExp("([0]*)([0-9]+)", "g"), "$2");
            let reg4 = /^[0-9]\d{0,5}$/;
            let flag4 = reg4.test(value);
            if (value == "00") {
              this.form.min_num = "0";
            }
            //
            if (!flag4) {
              callback(new Error("请输入大于0的数,且最大999999"));
              break;
            }
            this.temp.min_num = this.form.min_num;
            callback();
            break;
          case "exchange":
            if (!/^[0-9]+$/.test(value)) {
              this.form.exchange = this.temp.exchange;

              callback();
              break;
            }

            this.piece_exchange_check = false;
            this.form.exchange = value.replace(/[^\d.]/g, "");

            if (value == "0") {
              this.form.exchange = "";
              callback(new Error("请输入大于0的正整数,且最大为999999"));
              break;
            }
            let reg5 = /^[0-9]\d{0,5}$/;
            let flag5 = reg5.test(value);

            if (!flag5) {
              callback(new Error("请输入大于0的正整数,且最大为999999"));
              break;
            }
            this.piece_exchange_check = true;
            this.temp.exchange = this.form.exchange;
            callback();
            break;
          case "default_sell_number":
            if (value) {
              if (!/^[0-9]+$/.test(value)) {
                // this.form.default_sell_number = this.temp.default_sell_number;
                callback();
                break;
              }
            }
            this.temp.default_sell_number = this.form.default_sell_number;
            break;
          case "dose":
            if (value) {
              if (!/^[0-9]+$/.test(value)) {
                callback();
                break;
              }
            }
            this.temp.dose = this.form.dose;
            break;
        }
      }
    };

    return {
      boole: true,
      timer: 0,
      timer1: 0,
      id: 0,
      default_id: 0,
      wanrning: false,
      state: {
        drugs_management: { function_set: false }
      },
      cancelBool: false,
      dialogVisible: false,

      optionsCategory: [],
      optionsUse_type: [
        { label: "中西成药", value: 1 },
        { label: "饮片", value: 2 },
        { label: "注射液", value: 3 }
      ],
      temp: {
        temp: "",
        number: "",
        min_num: "",
        exchange: "",
        default_sell_number: "",
        dose: ""
      },

      form: {
        use_type: "",
        product_name: "",
        category_id: null,
        id: "0",
        default_id: "0",
        self_category: "",
        otc: true,
        pack: "",
        number_unit: "",
        production: "",
        expire_time: "",
        approval: "",
        bar_code: "",
        batch_no: "",
        number: "",
        split_piece: false,
        exchange: "",
        piece_unit: "",
        buy_price: "",
        price: "",
        min_num: "",
        supplier: "",
        shelf_no: "",
        usage: "",
        dose: "",
        dose_unit: "",
        rate: "",
        default_sell_number: "",
        default_sell_number_unit: "",
        advice: "",
        product_status: true
      },

      rules: {
        number_unit: [
          {
            required: true,
            message: "请输入规格包装并填写/选择右侧单位",
            trigger: "change"
          }
        ],
        number: [{ required: true, validator: numberCheck, trigger: "change" }],
        buy_price: [
          { required: true, validator: numberCheck, trigger: "change" }
        ],
        price: [{ required: true, validator: numberCheck, trigger: "blur" }],
        min_num: [
          { required: true, validator: numberCheck, trigger: "change" }
        ],
        dose: [{ required: false, validator: numberCheck, trigger: "change" }],
        product_name: [
          { required: true, message: "请输入/选择药品名称", trigger: "change" }
        ],
        category_id: [
          { required: true, message: "请选择药品类型", trigger: "change" }
        ],
        use_type: [
          {
            required: true,
            /*  message: "请选择用药类型", */ validator: numberCheck,
            trigger: "change"
          }
        ],
        pack: [
          {
            required: true,
            message: "请输入包装规格",
            trigger: "change"
          }
        ],
        default_sell_number: [
          {
            required: false,
            validator: numberCheck,
            trigger: "change"
          }
        ],
        expire_time: [
          { required: true, message: "请选择有效期", trigger: "change" }
        ],
        production: [
          { required: true, message: "请输入生产厂家", trigger: "change" }
        ],

        exchange: [
          { required: false, validator: numberCheck, trigger: "change" }
        ],
        piece_unit: [
          {
            required: false,
            message: "请填写/输入小包装单位",
            trigger: "change"
          }
        ]
      },
      pickerOptions: {
        disabledDate(time) {
          //此条为设置禁止用户选择今天之前的日期，包含今天。
          return time.getTime() <= Date.now() - 8.64e7;
        }
      },
      piece_unit_check: true,
      piece_exchange_check: false,
      bool: false,
      value: "",
      options: [],
      select: "盒",
      adv: {
        product_name: [],
        self_category: [],
        pack: [],
        number_unit: [],
        production: [],
        expire_time: "2021-10-01",
        approval: [],
        bar_code: [],

        number: [],
        exchange: [],
        piece_unit: [],
        buy_price: [],
        price: [],
        min_num: [],
        supplier: [],
        shelf_no: [],
        usage: [],
        usage1: [],
        dose: [],
        dose_unit: [],

        rate: [],
        default_sell_number: [],
        default_sell_number_unit_value: "",
        advice: []
      }
    };
  },
  watch: {
    $route(to, from) {
      // 路由发生变化页面刷新
      this.$router.go(0);
    },
    "form.product_name"() {
      this.cancelBool = true;
    },
    "form.split_piece"() {
      if (this.form.split_piece == false) {
        this.form.exchange = "";
        this.form.piece_unit = "";
        this.form.default_sell_number_unit = this.form.number_unit;
        this.rules.exchange[0].required = false;
        this.rules.piece_unit[0].required = false;
      } else {
        this.rules.exchange[0].required = true;
        this.rules.piece_unit[0].required = true;
        if (this.form.piece_unit != "") {
          this.form.default_sell_number_unit = this.form.piece_unit;
        } else {
          this.form.default_sell_number_unit = this.form.number_unit;
        }
      }
    },
    "form.number_unit"() {
      if (this.form.number_unit == "" && this.form.piece_unit != "") {
        this.form.default_sell_number_unit = this.form.piece_unit;
      }
      if (this.form.number_unit != "" && this.form.piece_unit == "") {
        this.form.default_sell_number_unit = this.form.number_unit;
      }
    },
    "form.exchange"() {
      this.bool = false;
    },
    "form.piece_unit"() {
      if (this.form.piece_unit == "") {
        this.bool = true;
      } else {
        this.bool = false;
      }

      if (this.form.split_piece == true && this.form.piece_unit != "") {
        this.form.default_sell_number_unit = this.form.piece_unit;
      }
    }
  },
  computed: {
    default_sell_number() {
      return this.form.default_sell_number == "" ? "" : "default_sell_number";
    },

    exchange() {
      if (this.bool == true) {
        return "piece_unit";
      } else {
        return "exchange";
      }
    },
    pack() {
      if (this.form.number_unit == "") {
        return "number_unit";
      } else {
        return "pack";
      }
    },
    default_sell_number_unit_options() {
      if (this.form.split_piece == false) {
        return [{ label: this.form.number_unit, value: this.form.number_unit }];
      } else {
        if (this.form.piece_unit != "" && this.form.number_unit != "") {
          return [
            { label: this.form.number_unit, value: this.form.number_unit },
            {
              label: this.form.piece_unit,
              value: this.form.piece_unit
            }
          ];
        } else if (this.form.piece_unit == "") {
          return [
            { label: this.form.number_unit, value: this.form.number_unit }
          ];
        } else {
          return [{ label: this.form.piece_unit, value: this.form.piece_unit }];
        }
      }
    },
    unit() {
      if (this.form.split_piece == false) {
        return this.form.number_unit;
      } else {
        return this.form.piece_unit;
      }
    },
    price_unit() {
      if (this.form.split_piece == false) {
        return "元/" + this.form.number_unit;
      } else {
        return "元/" + this.form.piece_unit;
      }
    },
    unitEnd() {
      return this.form.split_piece ? "/" + this.form.number_unit : "";
    }
  },
  methods: {
    inputClear(val) {
      if (this.form[val] == "0" || this.form[val] == 0) {
        this.form[val] = "";
      }
    },

    /*    usageMethod (val) {
               this.form.usage = val
           }, */

    exchangeFocus() {
      this.piece_exchange_check = false;
      this.bool = false;
    },

    exchangeBlur() {
      if (this.piece_exchange_check == true) {
        this.bool = true;
      } else {
        this.bool = false; //校验单位
      }
      setTimeout(_ => {
        this.$refs.form2.validate(_ => {});
        this.$refs.form1.validate(_ => {});
        this.$refs.form5.validate(_ => {});
      }, 100);
    },
    unitCheck() {
      if (this.form.split_piece != false) {
        if (this.form.piece_unit == this.form.number_unit) {
          this.form.piece_unit = "";
          this.default_sell_number_unit = this.form.number_unit;
          return this.$message.error(
            "包装单位和拆零单位不能相同，请修改拆零单位"
          );
        }
      } else {
        this.form.default_sell_number_unit = this.form.number_unit;
      }
    },
    unitCheckUsage(val) {
      this.form.usage = val;
    },
    remoteMethodUsage(query) {
      let Arr = this.adv.usage;
      if (query !== "") {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;

          this.adv.usage = [];
          this.adv.usage = Arr.filter(item => {
            return item.label.indexOf(query.toLowerCase()) > -1;
          });
        }, 200);
      } else {
        this.adv.usage = [];
      }
      this.adv.usage = [];
      this.adv.usage = Arr;

      this.unitCheckUsage(query);
    },
    unitCheck1(val) {
      this.form.number_unit = val;
      if (this.form.split_piece != false) {
        if (this.form.piece_unit == this.form.number_unit) {
          this.form.piece_unit = "";
          this.default_sell_number_unit = this.form.number_unit;
          return this.$message.error(
            "包装单位和拆零单位不能相同，请修改拆零单位"
          );
        }
      } else {
        this.form.default_sell_number_unit = this.form.number_unit;
      }
    },
    unitCheck2(val) {
      this.form.piece_unit = val;
      if (this.form.split_piece != false) {
        if (this.form.piece_unit == this.form.number_unit) {
          this.form.piece_unit = "";
          this.default_sell_number_unit = this.form.number_unit;
          return this.$message.error(
            "包装单位和拆零单位不能相同，请修改拆零单位"
          );
        }
      } else {
        this.form.default_sell_number_unit = this.form.number_unit;
      }
    },
    handleSelect() {},
    //药品名称输入联想
    inputLenvo() {
      if (this.form.product_name == "" || this.form.product_name == " ") {
        this.form.product_name = "";
        return;
      }
      lenvo({ prefix: this.form.product_name, size: 10 }).then(res => {
        this.adv.product_name = [];

        if (res.code == 200) {
          this.adv.product_name =
            res.data.ElasticProduct == null ? [] : res.data.ElasticProduct;
          if (this.adv.product_name.length != 0) {
            this.adv.product_name.forEach(ele => {
              this.temp.temp = ele.product_name;
              ele.value =
                ele.product_name +
                " (" +
                ele.pack +
                ") (" +
                ele.production +
                ")";
            });
          }
        } else {
          this.form = {
            category_id: null,
            id: "0",
            default_id: "0",
            self_category: "",
            otc: true,
            pack: "",
            number_unit: "",
            production: "",
            expire_time: "",
            approval: "",
            bar_code: "",
            batch_no: "",
            number: "",
            split_piece: false,
            exchange: "",
            piece_unit: "",
            buy_price: "",
            price: "",
            min_num: "",
            supplier: "",
            shelf_no: "",
            usage: "",
            dose: "",
            dose_unit: "",
            rate: "",
            default_sell_number: "",
            default_sell_number_unit: "",
            advice: "",
            product_status: true
          };
        }
      });
      clearTimeout(this.timer1);
    },
    async dataCheck(num) {
      clearTimeout(this.timer1);
      if (
        this.form.product_name != "" &&
        this.form.pack != "" &&
        this.form.production != "" &&
        this.form.approval != ""
      ) {
        matchDefaultId({
          product_name: this.form.product_name,
          pack: this.form.pack,
          production: this.form.production,
          approval: this.form.approval
        }).then(async res => {
          if (res.data.id != 0) {
            if (res.data.Own == true) {
              if (
                this.$route.query.id == undefined ||
                (this.$route.query != undefined &&
                  this.$route.query.id != res.data.id &&
                  this.$route.query != undefined &&
                  this.default_id != res.data.id)
              ) {
                this.wanrning = true;
              } else {
                this.wanrning = false;
              }
            } else {
              this.wanrning = false;
            }

            (this.form.category_name = res.data.category_name),
              (this.form.default_id = res.data.id),
              /*   (this.form.self_category = res.data.self_category), */
              (this.form.otc = res.data.otc),
              (this.form.pack = res.data.pack),
              (this.form.number_unit = res.data.number_unit),
              (this.form.production = res.data.production),
              (this.form.approval = res.data.approval),
              (this.form.bar_code = res.data.bar_code),
              //  this.form.number = res.data.number.toString(),
              //this.form.price = res.data.price,
              (this.form.usage = res.data.usage),
              (this.form.dose = res.data.dose.toString()),
              (this.form.dose_unit =
                res.data.dose == "" ? "" : res.data.dose_unit),
              (this.form.rate = res.data.rate),
              (this.form.default_sell_number = res.data.default_sell_number.toString()),
              (this.form.default_sell_number_unit =
                res.data.default_sell_number_unit),
              (this.form.advice = res.data.advice);
            this.form.product_name = res.data.product_name;
            this.optionsCategory.every(itm => {
              if (itm.category_name == this.form.category_name) {
                this.form.category_id = itm.ID;
              }
              return itm.category_name != this.form.category_name;
            });
          } else {
            this.form.default_id = 0;
            this.wanrning = false;
          }
          console.log(res.data.id);

          if (
            this.wanrning ==
              true /* && (this.$route.query.id != res.data.id) */ &&
            this.default_id != res.data.id
          ) {
            let tip = "该药品已存在,请选择 编辑药品 或继续新增并修改输入项";

            let info1 = "编辑药品"; //确定
            let info2 = "继续新增"; //取消
            if (this.$route.query.id != undefined) {
              tip = "该药品已存在,请选择 编辑已存在药品 或继续编辑并修改输入项";
              info1 = "编辑已存在药品";
              info2 = "继续编辑";
            }
            const confirm = await this.$confirm(tip, "提示", {
              confirmButtonText: info1,
              cancelButtonText: info2,
              type: "warning"
            }).catch(err => err);

            if (confirm !== "confirm") {
            } else {
              return this.$router.push({
                path: "/drugsManagement/newDrugs",
                query: {
                  id: this.form.default_id,
                  idenfine: true
                }
              });
            }
          }
        });
      } else {
        this.wanrning = false;
      }
      return this.wanrning;
    },
    inputLenvoOther(val) {
      console.log(val);
      if (this.form[val] == " ") {
        this.form[val] = "";
        return;
      }

      lenvoOther({ prefix: this.form[val], size: 10, tab: [val] }).then(res => {
        this.adv[val] = [];
        if (res.code == 200) {
          if (res.data.length != 0) {
            res.data.forEach(item => {
              this.adv[val].push({ value: item });
            });
          } else {
            if (this.$route.query == undefined) {
              this.form.default_id = 0;
            }

            this.wanrning = false;
          }
        } else {
        }
      });
    },
    //输入联想chang事件
    selfCategoryLenvo() {},
    async changeLenvo() {
      clearTimeout(this.timer1);

      let bol = false;
      this.adv.product_name.every(item => {
        if (
          /* this.form.product_name.indexOf(item.product_name) != -1 &&
            this.form.product_name.indexOf(item.pack) != -1 &&
            this.form.product_name.indexOf(item.production) != -1 */
          this.form.product_name == item.value
        ) {
          bol = true;
          if (item.Own == true) {
            if (
              this.$route.query.id == undefined ||
              (this.$route.query.id != item.id && this.default_id != item.id)
            ) {
              this.wanrning = true;
            } else {
              this.wanrning = false;
            }
          } else {
            this.wanrning = false;
          }
          (this.form.category_name = item.category_name),
            (this.form.default_id = item.id),
            // (this.form.id=item.id),
            // (this.id = item.id),
            (this.form.self_category = item.self_category),
            (this.form.otc = item.otc),
            (this.form.pack = item.pack),
            (this.form.number_unit = item.number_unit),
            (this.form.production = item.production),
            (this.form.approval = item.approval),
            (this.form.bar_code = item.bar_code),
            //  this.form.number = item.number.toString(),
            //this.form.price = item.price,
            (this.form.usage = item.usage),
            (this.form.dose = item.dose.toString()),
            (this.form.dose_unit = item.dose_unit),
            (this.form.rate = item.rate),
            (this.form.default_sell_number = item.default_sell_number.toString()),
            (this.form.default_sell_number_unit =
              item.default_sell_number_unit),
            (this.form.advice = item.advice);
          this.form.product_name = item.product_name;
        }

        return bol == false;
      });
      this.optionsCategory.every(itm => {
        if (itm.category_name == this.form.category_name) {
          this.form.category_id = itm.ID;
        }
        return itm.category_name != this.form.category_name;
      });
      this.timer1 = setTimeout(_ => {
        this.dataCheck("2");
      }, 200);
    },
    //save时，如果id为0则为保存，否则为编辑
    querySearch(queryString, cb, val) {
      let restaurants;
      switch (val) {
        case "product_name":
          restaurants = this.adv.product_name;
          break;

        case "pack":
          restaurants = this.adv.pack;
          break;

        case "self_category":
          restaurants = this.adv.self_category;
          break;

        case "production":
          restaurants = this.adv.production;
          break;

        case "approval":
          restaurants = this.adv.approval;
          break;

        case "bar_code":
          restaurants = this.adv.bar_code;
          break;

        case "number":
          restaurants = this.adv.number;
          break;

        case "exchange":
          restaurants = this.adv.exchange;
          break;

        case "buy_price":
          restaurants = this.adv.buy_price;
          break;

        case "price":
          restaurants = this.adv.price;
          break;

        case "min_num":
          restaurants = this.adv.min_num;
          break;

        case "supplier":
          restaurants = this.adv.supplier;
          break;
        case "shelf_no":
          restaurants = this.adv.shelf_no;
          break;

        case "dose":
          restaurants = this.adv.dose;
          break;

        case "default_sell_number":
          restaurants = this.adv.default_sell_number;
          break;
        case "advice":
          restaurants = this.adv.advice;
          break;
        case "usage":
          restaurants = this.adv.usage;
          break;
        case "rate":
          restaurants = this.adv.rate;
          break;
        case "dose_unit":
          restaurants = this.adv.dose_unit;
          break;
        case "advice":
          restaurants = this.adv.advice;
          break;
      }

      let string = "usage,rate,advice,dose_unit";
      if (string.indexOf(val) != -1) {
        var results = queryString
          ? restaurants.filter(this.createFilter2(queryString))
          : restaurants;
      } else if (val == "self_category") {
        var results = queryString
          ? restaurants.filter(this.createFilter3(queryString))
          : restaurants;
      } else {
        var results = queryString
          ? restaurants.filter(this.createFilter(queryString))
          : restaurants;
      }

      //   var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
      // 调用 callback 返回建议列表的数据

      cb(results);
    },

    createFilter(queryString) {
      return restaurant => {
        return 1;
        // return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0 || restaurant.name_pinyin.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      };
    },
    createFilter2(queryString) {
      return restaurant => {
        return restaurant.label.indexOf(queryString) != -1;
      };
    },
    createFilter3(queryString) {
      return restaurant => {
        return restaurant.value.indexOf(queryString) != -1;
      };
    },
    //保存按钮
    async saveDia() {
      let bool = true;

      this.$refs.form5.validate(valid => {
        console.log("-------");
        if (!valid) {
          this.boole = valid;
        }
      });

      this.$refs.form1.validate(valid => {
        if (!valid) {
          bool = valid;
        }
      });

      if (this.state.drugs_management.function_set == true) {
        this.$refs.form3.validate(valid => {
          if (!valid) {
            bool = valid;
          }
        });
      } else {
        this.$refs.form2.validate(valid => {
          if (!valid) {
            bool = valid;
          }
        });
      }

      if (bool != true || this.boole !== true) {
        return;
      }
      if (this.form.number_unit == "") {
        return this.$message.error("包装规格单位不能为空");
      }
      if (this.form.split_piece == true && this.form.piece_unit == "") {
        return this.$message.error("拆零单位不能为空");
      }

      if (
        this.form.product_name != "" &&
        this.form.pack != "" &&
        this.form.production != "" &&
        this.form.approval != ""
      ) {
        matchDefaultId({
          product_name: this.form.product_name,
          pack: this.form.pack,
          production: this.form.production,
          approval: this.form.approval
        }).then(async res => {
          /* &&this.$route.query.id==undefined||(res.data.Own==true&&((this.$route.query.id!=item.id)||(this.default_id!=item.id))) */
          /*    if(res.data.Own==true){
                   this.wanrning=true
               }else */
          this.form.default_id = res.data.id;
          if (
            res.data.Own != true ||
            (res.data.Own == true &&
              (this.$route.query.id == res.data.id ||
                this.default_id == res.data.id))
          ) {
            this.wanrning = false;
            let tip = "确认要保存吗";

            const confirm = await this.$confirm(tip, "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).catch(err => err);

            if (confirm !== "confirm") {
              return this.$message.info("已取消");
            }
            this.save();
          } else {
            this.wanrning = true;
          }
        });
      } else {
        let tip = "确认要保存吗";

        const confirm = await this.$confirm(tip, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).catch(err => err);

        if (confirm !== "confirm") {
          return this.$message.info("已取消");
        }
        this.save();
      }
    },
    save() {
      console.log(this.form.default_id);

      let form = {};
      // return
      if (this.$route.query.id == undefined) {
        form = {
          use_type: this.form.use_type,
          product_name: this.form.product_name,
          category_id: Number(this.form.category_id),
          id: 0,
          default_id: Number(this.form.default_id),
          self_category: this.form.self_category,
          otc: this.form.otc,
          pack: this.form.pack,
          number_unit: this.form.number_unit,
          production: this.form.production,
          expire_time: this.form.expire_time,
          approval: this.form.approval,
          bar_code: this.form.bar_code,
          batch_no: this.form.batch_no,
          number: Number(this.form.number),
          split_piece: this.form.split_piece,
          exchange: Number(this.form.exchange),
          piece_unit: this.form.piece_unit,
          buy_price: Number(this.form.buy_price),
          price: Number(this.form.price),
          min_num: Number(this.form.min_num),
          supplier: this.form.supplier,
          shelf_no: this.form.shelf_no,
          usage: this.form.usage,
          dose: this.form.dose + "",
          dose_unit: this.form.dose_unit,
          rate: this.form.rate,
          default_sell_number: Number(this.form.default_sell_number),
          default_sell_number_unit: this.form.default_sell_number_unit,
          advice: this.form.advice,
          product_status: this.form.product_status
        };
      } else {
        form = {
          use_type: this.form.use_type,
          product_name: this.form.product_name,
          category_id: Number(this.form.category_id),
          id: Number(this.id),
          default_id: Number(this.form.default_id),
          self_category: this.form.self_category,
          otc: this.form.otc,
          pack: this.form.pack,
          number_unit: this.form.number_unit,
          production: this.form.production,
          expire_time: this.form.expire_time,
          approval: this.form.approval,
          bar_code: this.form.bar_code,
          batch_no: this.form.batch_no,
          number: Number(this.form.number),
          split_piece: this.form.split_piece,
          exchange: Number(this.form.exchange),
          piece_unit: this.form.piece_unit,
          buy_price: Number(this.form.buy_price),
          price: Number(this.form.price),
          min_num: Number(this.form.min_num),
          supplier: this.form.supplier,
          shelf_no: this.form.shelf_no,
          usage: this.form.usage,
          dose: this.form.dose + "",
          dose_unit: this.form.dose_unit,
          rate: this.form.rate,
          default_sell_number: Number(this.form.default_sell_number),
          default_sell_number_unit: this.form.default_sell_number_unit,
          advice: this.form.advice,
          product_status: this.form.product_status
        };
      }

      //this.dialogVisible = false;
      /*  if (
          form.product_name != "" &&
          form.pack != "" &&
          form.production != "" &&
          form.approval != ""
        ) {
          matchDefaultId({
            product_name: form.product_name,
            pack: form.pack,
            production: form.production,
            approval: form.approval
          }).then(res => {
            form.default_id = res.data.id;
            this.newDrugsData(form);
          });
        } else {
          this.newDrugsData(form);
        } */
      this.newDrugsData(form);
    },
    newDrugsData(data) {
      newDrugs(data).then(res => {
        if (res.code == 200) {
          /*  if (this.$route.query.id != undefined) {
                   this.$message.success('编辑成功')
               } else {
                   this.$message.success('新增成功')
               } */
          this.$router.push({ name: "drugInformationManagement" });
        } else {
          if (this.$route.query.id != undefined) {
            this.$message.success("编辑失败");
          } else {
            this.$message.success("新增失败");
          }
        }
      });
    },
    //取消按钮
    async goBack() {
      if (this.cancelBool == true && this.$route.query.id == undefined) {
        const confirm = await this.$confirm(
          "数据已发生改动，确认不保存吗",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }
        ).catch(err => err);
        if (confirm == "confirm" && this.$route.query.id == undefined) {
          return this.$router.push({ name: "drugInformationManagement" });
        }
      } else {
        return this.$router.push({ name: "drugInformationManagement" });
      }
    },
    // getDrugsDetailData_default_id(id){},
    //获取药品详情信息
    getDrugsDetailData(id) {
      getDrugsDetail(id).then(res => {
        if (res.code == 200) {
          this.default_id = res.data.default_id;
          this.id = res.data.id;
          this.form = {
            product_name: res.data.product_name,
            category_id: Number(res.data.category_id),
            id: res.data.id.toString(),
            default_id: res.data.default_id.toString(),
            self_category: res.data.self_category,
            otc: res.data.otc,
            pack: res.data.pack,
            number_unit: res.data.number_unit,
            production: res.data.production,
            expire_time: res.data.expire_time,
            approval: res.data.approval,
            bar_code: res.data.bar_code,
            batch_no: res.data.batch_no,
            number: res.data.number.toString(),
            split_piece: res.data.split_piece,
            exchange:
              res.data.exchange != undefined
                ? res.data.exchange.toString()
                : "",
            piece_unit: res.data.split_piece == true ? res.data.piece_unit : "",
            buy_price: res.data.buy_price.toString(),
            price: res.data.price.toString(),
            min_num: res.data.min_num.toString(),
            supplier: res.data.supplier,
            shelf_no: res.data.shelf_no,
            usage: res.data.usage,
            dose: res.data.dose.toString(),
            dose_unit: res.data.dose_unit,
            rate: res.data.rate,
            default_sell_number: res.data.default_sell_number.toString(),
            default_sell_number_unit: res.data.default_sell_number_unit,
            advice: res.data.advice,
            use_type: res.data.use_type,
            // product_status: res.data.product_status != undefined ? res.data.product_status.toString() : '',
            product_status: res.data.product_status
          };
        }
      });
    },
    async getDrugsCategoryData() {
      const res = await getDrugsCategory();
      if (res.code === 200) {
        this.optionsCategory = res.data;
        this.optionsCategory.every(item => {
          if (item.category_name == "全部") {
            item.disabled = true;
          }
          return item.category_name != "全部";
        });
      }
    }
  },
  activated() {},
  created() {
    self_categoryLenvo().then(res => {
      this.adv.self_category = [];

      if (res.code == 200) {
        if (res.data.length != []) {
          res.data.forEach(item => {
            this.adv.self_category.push({ value: item });
          });
        }
      }
    });

    getJson().then(res => {
      this.adv.number_unit = []; //大单位
      this.adv.piece_unit = []; //小单位
      this.adv.usage = []; //用法
      this.adv.dose_unit = []; //剂量单位
      this.adv.rate = []; //使用频次
      this.adv.advice = []; //医嘱
      if (res.data) {
        res.data.number_unit.forEach(item => {
          this.adv.number_unit.push({
            label: item,
            value: item
          });
        });
        res.data.piece_unit.forEach(item => {
          this.adv.piece_unit.push({
            label: item,
            value: item
          });
        });
        res.data.usage.forEach(item => {
          this.adv.usage.push({
            label: item,
            value: item
          });
        });
        res.data.dose_unit.forEach(item => {
          this.adv.dose_unit.push({
            label: item,
            value: item
          });
        });
        res.data.eat_rate.forEach(item => {
          this.adv.rate.push({
            label: item,
            value: item
          });
        });
        res.data.advice.forEach(item => {
          this.adv.advice.push({
            label: item,
            value: item
          });
        });
      }
    });

    this.state = JSON.parse(this.$store.getters.systemSetting.dic_value);
    this.getDrugsCategoryData();
    if (this.$route.query.id !== undefined) {
      if (this.$route.query.idenfine == "true") {
        this.getDrugsDetailData({ default_id: this.$route.query.id });
        // this.form.id = this.$route.query.id;
      } else {
        this.getDrugsDetailData({ product_id: this.$route.query.id });
        this.form.id = this.$route.query.id;
      }
    }
  }
};
</script>
<style></style>
<style lang="scss" scoped>
@import "@/assets/scss/drugsManagement/newDrugs.scss";
</style>
